package top.lunarye.support.utils;

import org.springframework.stereotype.Component;
import top.lunarye.support.config.ThreadPoolExecutorShutdownDefinition;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 线程池工具类
 * @author lunar
 * @since 2022-07-18
 */
@Component
public class ThreadPoolUtils {

    private ThreadPoolExecutorShutdownDefinition shutdownDefinition;

    private static final String SOURCE_NAME = "message";

    /**
     * 将线程池注册，使其被Spring管理，方便在容器关闭的时候优雅地关闭线程池
     * @param executor
     */
    public void register(ExecutorService executor) {
        shutdownDefinition.registryExecutor(executor);
    }
}
